﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ServiceModel;
using UpYourLife.ViewModels;
using UpYourLife.UpYourLifeServices;

namespace UpYourLife
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = new MainViewModel();            
        }

        private void MapButton_Click(object sender, EventArgs e)
        {
            //this.GoToPage(ApplicationPages.Map);
            UpYourLifeServicesClient proxy = new UpYourLifeServicesClient(new BasicHttpBinding(), new EndpointAddress("http://localhost:8080/UpYourLife"));
            proxy.GetPlaceAsync(new Guid("2fdb6371-4758-403d-b722-80cde95bf0b8"));
            proxy.GetPlaceCompleted += new EventHandler<GetPlaceCompletedEventArgs>(proxy_GetPlaceCompleted);
        }

        void proxy_GetPlaceCompleted(object sender, GetPlaceCompletedEventArgs e)
        {
            Place place = e.Result;
        }

        private void MainMenuListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var item = (MainMenuItemViewModel)e.AddedItems[0];

                //var _root = Application.Current.RootVisual as PhoneApplicationFrame;
                //var tran = (TransitioningContentControl)VisualTreeHelper.GetChild(_root, 0);
                //tran.Transition = item.LineOne == "Log Out" ? "SlideRight" : "SlideLeft";
                if (!string.IsNullOrEmpty(item.TargetView))
                {
                    NavigationService.Navigate(new Uri("/" + item.TargetView, UriKind.RelativeOrAbsolute));
                }
            }
        }

        private void MessageListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}